//
//  ButtonFiveTableViewCell.m
//  WWAVPlayer
//
//  Created by dllo on 15/10/30.
//  Copyright © 2015年 LZY. All rights reserved.
//

#import "ButtonFiveTableViewCell1.h"
#import <UIImageView+WebCache.h>
#import <UIButton+WebCache.h>
#import "ButtonFiveCollectionViewCell.h"
#import "Blocks.h"
@interface ButtonFiveTableViewCell()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (nonatomic,strong) UIButton *button;
@property (nonatomic,strong) UICollectionViewFlowLayout *flow;
@end
@implementation ButtonFiveTableViewCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.flow = [[UICollectionViewFlowLayout alloc] init];
        _flow.itemSize = CGSizeMake(Screen_Width / 5, self.contentView.bounds.size.height);
        _flow.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        _flow.minimumInteritemSpacing = 0;
        _flow.minimumLineSpacing = 0;
        
        self.collectionView = [[UICollectionView alloc] initWithFrame:self.contentView.bounds collectionViewLayout:_flow];
        self.collectionView.delegate = self;
        self.collectionView.dataSource = self;
        [self.contentView addSubview:self.collectionView];
        
        [self.collectionView registerClass:[ButtonFiveCollectionViewCell class] forCellWithReuseIdentifier:@"button"];
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    _flow.itemSize = CGSizeMake(Screen_Width / 5, self.contentView.bounds.size.height);
    self.collectionView.frame = self.contentView.bounds;
    
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 5;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ButtonFiveCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"button" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    cell.buttonNameLabel.text = [_buttonNameArr objectAtIndex:indexPath.row];
    [cell.photoImageView sd_setImageWithURL:[NSURL URLWithString:[self.buttonImageArr objectAtIndex:indexPath.row]]];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    Blocks *block = [[Blocks alloc] init];
    
    block = [self.dataArr objectAtIndex:indexPath.row];
    
    [self.delegate passToCollectionWithBlock:block];
    
}






@end
